#include <stdio.h>
#include <stdlib.h>

typedef struct stu
{
    int num;
    int score;
    char name[20];
    struct stu *next;
} STU;

void link_create_head(STU **phead, STU *pnew);
void print_link(STU *phead);

int main()
{
    STU *p_head = NULL, *p_new = NULL;
    int total_stu = 0, i;
    printf("please enter how much stu\n");
    scanf("%d", &total_stu);

    for (i = 0; i < total_stu; i++)
    {
        p_new = (STU *)malloc(sizeof(STU));
        if (p_new == NULL)
            return 0;

        printf("please enter stu num  score  name\n");
        scanf("%d %d %s", &p_new->num, &p_new->score, &p_new->name);
        
        link_create_head(&p_head, p_new);
    }

    print_link(p_head);

    system("pause");
}

void link_create_head(STU **phead, STU *pnew)
{
    STU *pmove = *phead;
    if (*phead == NULL)
    {
        *phead = pnew;
        pnew->next = NULL;
    }
    else
    {
        while (pmove->next != NULL)
        {
            pmove = pmove->next;
        }

        pmove->next = pnew;
        pnew->next = NULL;
    }
}

void print_link(STU *phead)
{
    STU *pmove = phead;
    while (pmove != NULL)
    {
        printf("the stu info: %d %d %s\n", pmove->num, pmove->score, pmove->name);
        pmove = pmove->next;
    }
}